<?php
// 9/10/2009: Immanuel192 write this module

class storemodule {
	function name() { return "Ecomercial Module";  }
	function description() { return "Basket, online payment,...";  }
	function author() { return "Immanuel192 - Absoft.vn"; }
	
	function hasContent() { return false; }
	function hasSources() { return false; }
	function hasViews()   { return true; }
	
	function supportsWorkflow() { return false; }
	
	function permissions($internal = "") {
		$permissions = array(
        'administrate'=>'Administrator'
    );
		return $permissions;
	}
	
	function show($view,$loc,$title = '') {
	  global $user;
		$template = new template('storemodule',$view,$loc);
    global $db;
    // get all cache
    $ticket=exponent_sessions_getTicketString();
    $cache=$db->selectObjectsBySql("
       SELECT {$db->prefix}album.*,
              {$db->prefix}album_format.name as format_name,
              {$db->prefix}order_cache.* FROM {$db->prefix}order_cache INNER JOIN {$db->prefix}album ON {$db->prefix}order_cache.item_id = {$db->prefix}album.id INNER JOIN {$db->prefix}album_format ON {$db->prefix}album_format.id={$db->prefix}album.format WHERE ticket_string='{$ticket}'");
    // generate icon
    foreach ($cache as $key=>$value){
      // set icon
      if (strpos(strtolower($value->format_name),"dvd") >= 0)
        $value->icon="dvd";
      else if (strpos(strtolower($value->format_name),"cd") >= 0)
         $value->icon="dvd";
      else
         $value->icon="music";
      
      $cache[$key]=$value;
    }
    
    // get ship fee
    $is_logged=exponent_sessions_loggedIn();
    if ($is_logged){
     // get user location
     $country=strtolower($user->user_address->country);
     if ($country == "usa" || $country == "canada")
      $template->assign("ship_fee",0);
     else
      $template->assign("ship_fee",5);
    } else {
      $template->assign("ship_fee",5);
    }
    
    $template->assign("orders",$cache);
    $template->assign("order_count",count($cache));
    
    $template->assign("moduletitle",$title);
		$perms = storemodule::permissions();
		$template->register_permissions(array_keys($perms),$loc);
		$template->output($view);
	}
}

?>
